#ifndef __BULLET_CONFIG_H__
#define __BULLET_CONFIG_H__

#include <vector>
#include "../tinyxml/tinyxml.h"
#include "cocos2d.h"
namespace fishingjoy
{
	namespace config
	{
		struct SBulletData
		{
			float Speed;
			float Distance;
			int Atk;
			int Cost;
		};
		class CBulletConfig
		{
			static std::vector<SBulletData> m_vecBulletData;
			static void load()
			{
				if(m_vecBulletData.size()==0){
					TiXmlDocument doc;
					std::string pathKey = "config/bullet.xml"; 
					pathKey = cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pathKey.c_str());		
					//const char* pFile = cocos2d::CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("config/animations.xml");
					if(doc.LoadFile(pathKey.c_str())){
						TiXmlElement* root = doc.RootElement();
						if(root){
							TiXmlElement* pBulletNode = root->FirstChildElement();
							while(pBulletNode){
								m_vecBulletData.push_back(SBulletData());
								SBulletData& fd = m_vecBulletData[m_vecBulletData.size()-1];
								fd.Speed = atoi(pBulletNode->Attribute("speed"));
								fd.Distance = atoi(pBulletNode->Attribute("distance"));
								fd.Atk = atoi(pBulletNode->Attribute("atk"));
								fd.Cost = atoi(pBulletNode->Attribute("cost"));
								pBulletNode = pBulletNode->NextSiblingElement();
							}
						}
					}
				}
			}
		public:
			static const SBulletData* getData(int level)
			{
				if(level < 1 || level > 5){
					return NULL;
				}
				load();
				return &m_vecBulletData[level-1];
			}
		};
	}
}

#endif